package com.ehome.poct.core.pasre.report.symbol;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import com.ehome.poct.base.api.enums.StripTypeEnums;
import com.ehome.poct.core.api.dto.check.gold.TestConfPoctStripTypeDTO;
import com.ehome.poct.core.pasre.report.symbol.dto.ReportSymbolDTO;

import java.math.BigDecimal;

/**
 * @auther: kuiba.peng
 * @date: 2022/11/10 14:21
 * @description: 报告符号策略
 */
public interface SymbolStrategy {

    StripTypeEnums getStripType();

    default String getSymbol(ReportSymbolDTO reportSymbolDTO) {
        String reference = getReference(reportSymbolDTO);
        BigDecimal low = new BigDecimal(reference.substring(0, reference.indexOf("~")));
        BigDecimal high = new BigDecimal(reference.substring(reference.indexOf("~") + 1));

        BigDecimal checkResult = reportSymbolDTO.getCheckResult();
        if (low.compareTo(checkResult) > 0) {
            return "↓";
        }
        if (high.compareTo(checkResult) <= 0) {
            return "↑";
        }
        return "";
    }

    default String getReference(ReportSymbolDTO reportSymbolDTO) {
        TestConfPoctStripTypeDTO stripType = reportSymbolDTO.getConfPoctStripType();
        String reference = stripType.getReference();

        if (CharSequenceUtil.isEmpty(reference)) {
            //再取一次成人标准
            reference = stripType.getStandardReference();
        }
        if (reportSymbolDTO.isChild()) {
            reference = StrUtil.isNotEmpty(stripType.getChildReference()) ? stripType.getChildReference() : reference;
        }
        if (CharSequenceUtil.isEmpty(reference)) {
            return "";
        }
        return reference;
    }
}
